package main

import (
	"github.com/gin-gonic/gin"
	"github.com/micro/go-micro/registry"
	"github.com/micro/go-micro/registry/etcd"
	"github.com/micro/go-micro/v2/logger"
	"github.com/micro/go-micro/web"
	"microprj/groupWeatherArea/global"
	"microprj/groupWeatherArea/model"
	"microprj/lib/log"
	"microprj/lib/orm"
	"net/http"
	"time"
)

const NAME  = "go.micro.api.weather"

func init() {
	log.InitZap()
	db,err:=orm.InitMysql()
	if err !=nil {
		logger.Fatal(err.Error())
	}
	global.DB=db
}

func main()  {
	reg := etcd.NewRegistry(registry.Addrs("127.0.0.1:2379"))

	server:=web.NewService(
		web.Name(NAME),
		web.Registry(reg),
		web.RegisterTTL(time.Second*30),
		web.RegisterInterval(time.Second*10),
		)
	server.Handle("/",getHanderl())
	if err := server.Run(); err != nil {
		logger.Error(err)
	}
}

func getHanderl() http.Handler  {
	router:=gin.Default()
	r:=router.Group("/weather")
	r.GET("/getByInfo",GetAll)
	return router
}

func GetAll(c *gin.Context)  {
	logger.Info("get all")
	model.GetWeatherByCountry(nil)

	c.JSON(200, gin.H{
		"message": "message ",
		"token":   "token ",
	})
}
